<?php
/**
 * @apiVersion 1.0.0
 * @api {POST} /wechat/User/getUserInfo 004获取用户信息接口OK
 * @apiDescription 获取用户信息接口
 * @apiGroup Pub
 * @apiPermission 公众号

 * @apiSuccess  {Int} code 状态
 * @apiSuccess  {Object} data 元数据
 * @apiSuccess  {String} msg 错误说明
 * @apiSuccessExample {json} 响应示例:
{
    "code": 1,
    "msg": "登录成功",
    "data": {
        "userID": 237,  //用户id
        "photo": null,  //头像
        "mobile": "15573179664",  //手机号
        "nickname": null,  //昵称
        "sex": 0,  //性别：
        "trueName": "张三",  //真实姓名
        "card": "273273723723",  //身份证号码
        "updataTime": 1620157828,
        "addTime": 1620157741,  //注册时间
        "status": 1,      //状态： 1正常 0禁用
        "serialNumber": null,
        "appType": null,
        "mobileType": null,
        "password": null,
        "payPassword": null,
        "agent": null,
        "clientIP": "3740760482",
        "location": null,
        "judge": 0,
        "version": null,
        "latitude": null,
        "longitude": null,
        "apliayUsername": null, //支付宝账号
        "apliayPassword": null, //支付宝密码
        "apliayPayPassword": null,  //支付宝支付密码
        "wechatUsername": null, //微信账号
        "wechatPassword": null, //微信密码
        "wechatPayPassword": null,  //微信支付密码
        "depositUsername": null,    //提现账号
        "depositType": null,    //提现类型： 1支付宝 2微信
        "platformID": 0,    //平台id
        "statusCheck": -1,
        "xrkCode": null,    //葵码
        "checkTime": null,
        "checkManger": null,
        "cMobile": "",
        "depositRealname": "",
        "openID": null, //微信openid
        "unionID": null,    //开发平台id
        "loginTimes": 3,
        "lastLoginTime": 1620157828
    }
}

 * //操作未成功提示信息
 * {
 *      "code":0,
 *      "msg" :"错误说明"
 * }
 */




/**
 * @apiVersion 1.0.0
 * @api {POST} /wechat/Task/detail 3001任务详情OK
 * @apiDescription 详情
 * @apiGroup Task
 * @apiPermission 公众号
 * @apiParam {int} taskID 任务id
 * @apiParamExample {json} 请求示例:
 * {
 *      "taskID": 1,
 * }
 * @apiSuccess  {Int} code 状态
 * @apiSuccess  {Object} data 元数据
 * @apiSuccess  {String} msg 错误说明
 * @apiSuccessExample {json} 响应示例:
    {
        "code": 1,
        "msg": "操作成功",
        "data": {
        "count": 1,
        "list":
            {
                "taskID": 1,    //任务id
                "title": "一秒助力",    //任务标题
                "startYmd": "2021-05-01",    //开始时间
                "endYmd": "2021-06-05",    //结束时间
                "dayStart": "09:00",    //每天的开始时间
                "dayEnd": "23:00",    //每天的结束时间
                "times": 1,    //重复次数： 1每天一次 2 每周一次 3 每月一次  4 每年一次 5只能一次
                "logo": "1.png",    //任务logo图
                "type": 1,    //任务类型
                "video": null,    //视频链接
                "content": null,    //任务教程内容
                "standardImg": null,    //任务标准图
                "isOpen": 2,    //是否开放： 1开放 2不开放
                "rewardName": "按要求进行操作",    //悬赏名称
                "rewardMoney": "0.05",    //悬赏金额
                "rewardNum": 200,    //悬赏人数
                "checkManager": null,    //审核人员id
                "checkTime": null,    //审核时间
                "status": 1,    //状态: -1审核中 1通过 2驳回  9取消
                "isUp": 1,    //
                "addTime": "2018-07-16 10:22:37",    //
                "updateTime": "1970-01-01 08:00:00",    //
                "platformID": 1,    //
                "sort": 1,    //
                "label": "'财神到','超赞'",    //
                "typeName": null,    //
                "checkManagerName": null,    //
                "checkTimeStr": "",    //
                "statusText": "通过",    //
                "isUpText": "上架",    //
                "isOpenText": "不开放",    //
                "timesText": "每次一次",    //
                "num": 100,    //剩余次数
                "completeNUm": 80,    //completeNUm
            }
        }
    }

 * //操作未成功提示信息
 * {
 *      "code":0,
 *      "msg" :"错误说明"
 * }
 */

namespace app\wechat\controller;


use app\model\FreshAdminAuthGroupAccess;
use app\model\FreshAdminUser;

use app\model\FreshAdminUserData;
use app\util\ReturnCode;
use app\util\Tools;
use think\Db;

class Task extends Base {


    /**
     * 异常原因列表
     */
    public function index() {

        $where = [];
        $page = $this->request->get('page', 1);
        $size = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT'));
        $postData = $this->request->get();



        if(!isset($postData['type']))  return $this->buildFailed(ReturnCode::INVALID, '消息类型不能为空');
        if ($postData['type'] == 1) {
            $where['type'] = $postData['type'];
        }else{
            $where['type'] = $postData['type'];
            $where['userID'] = $this->userInfo['userID'];
        }



        $model = new \app\model\UserMsg();
        $list =  $model
            ->field('*')
            ->limit(( $page - 1 ) * $size , $size)
            ->order('addTime desc')
            ->where($where)
            ->select();


        $count  =  $model->where($where)->count();



        return $this->buildSuccess([
            'count'=>$count,
            'list'=>$list,
        ]);
    }

    public function detail(){
        $postData = $this->request->post();
        if(!isset($postData['taskID']))  return $this->buildFailed(ReturnCode::INVALID,'任务id不能为空');
//        $user = Db::name('user')->where('id', $postData['id'])->find();

        $data = \app\model\Task::get(['taskID' => $postData['taskID']]);
        if($data['status'] != 1) return $this->buildFailed(ReturnCode::INVALID, '任务状态异常');
        if($data['isUp'] != 1) return $this->buildFailed(ReturnCode::INVALID, '任务已下架');
        return $this->buildSuccess($data, '操作成功');
    }


}
